import 'package:flutter/material.dart';
import 'package:flutterproject/mvvm/base/base_state.dart';
import 'package:flutterproject/page/mine/children/assets/childdren/charge_page.dart';
import 'package:flutterproject/page/mine/children/assets/childdren/exchage/exchage_page.dart';
import 'package:flutterproject/page/mine/children/assets/childdren/score_four.dart';
import 'package:flutterproject/page/mine/children/assets/childdren/score_one.dart';
import 'package:flutterproject/page/mine/children/assets/childdren/score_three.dart';
import 'package:flutterproject/page/mine/children/assets/childdren/score_two.dart';
import 'package:flutterproject/page/mine/children/assets/childdren/transform/transform.dart';
import 'package:flutterproject/page/mine/children/assets/controller/my_assets_controller.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/app_bar_common.dart';
import 'package:flutterproject/widget/button_common.dart';
import 'package:flutterproject/widget/keep_alive_wrapper.dart';
import 'package:get/get.dart';

import 'childdren/score_five.dart';
import 'childdren/score_transform.dart';
import 'childdren/yun_charge/index.dart';
import 'childdren/zengzhi/zengzhi.dart';
import 'childdren/zengzhi/zengzhi_history.dart';

class MyAssetsPage extends BaseState<MyAssetsController> {
  @override
  MyAssetsController initController() => MyAssetsController();

  @override
  Widget initView(BuildContext context) {
    return DefaultTabController(
      length: 5,
      initialIndex: controller.currentIndex,
      child: Container(
        color: Color(0xFFF6F6F6),
        width: Get.width,
        child: Column(
          children: [
            AppBarCommon(
              title: "资产列表",
              bgColor: Color(0xFFEDC88B),
              leftColor: Colors.white,
              titleColor: Colors.white,
            ),
            10.heightBox,
            TabBar(
              tabs: controller.myTabs,
              indicatorColor: Color(0xFFEDC88B),
              labelColor: Color(0xFFEDC88B),
              unselectedLabelColor: Color(0xFF414141),
              padding: MarginPaddingUtil.all(0),
              labelPadding: MarginPaddingUtil.all(0),
              indicatorSize: TabBarIndicatorSize.label,
              indicatorPadding: MarginPaddingUtil.symmetric(vertical: 30.width),
              onTap: (index) => controller.changeIndex(index),
            ),
            Expanded(
              child: TabBarView(
                physics: NeverScrollableScrollPhysics(),
                children: [
                  KeepAliveWrapper(
                      child: ScoreOnePage(
                    bean: controller.assetsDetailBean,
                  )),
                  KeepAliveWrapper(
                      child: ScoreTwoPage(
                    bean: controller.assetsDetailBean,
                  )),
                  KeepAliveWrapper(
                      child: ScoreThreePage(
                    bean: controller.assetsDetailBean,
                  )),
                  KeepAliveWrapper(
                      child: ScoreFourPage(
                    bean: controller.assetsDetailBean,
                  )),
                  KeepAliveWrapper(
                      child: ScoreFivePage(
                    bean: controller.assetsDetailBean,
                  )),
                ],
              ),
            ),
            GetBuilder<MyAssetsController>(
                id: 'bottom',
                builder: (logic) {
                  return _buildBottom();
                })
          ],
        ),
      ),
    );
  }

  Widget _buildBottom() {
    switch (controller.currentIndex) {
      case 0:
        return _buildBottomOne();
      case 1:
        return _buildBottomTwo();
      case 2:
        return _buildBottomThree();
      case 3:
        return _buildBottomFour();
      case 4:
        return _buildBottomFive();
    }
    return Container();
  }

  Widget _buildBottomOne() {
    return Column(
      children: [
        Divider(
          color: Color(0xFFE8D1D1),
          height: 1.width,
        ),
        Container(
          color: Colors.white,
          padding: MarginPaddingUtil.symmetric(
            vertical: 21,
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Spacer(),
              ButtonCommon(
                text: '充值',
                onTap: () async {
                  await Get.to(YunCharge(
                    walletId: controller
                        .myAssetsBean.list?[controller.currentIndex].id,
                  ));
                  controller.getAssetsDetail();
                },
                width: 200.width,
                color: Color(0xFFF9B57B),
                borderRadios: 40.radius,
              ),
              10.widthBox,
              ButtonCommon(
                text: '互转',
                onTap: () {
                  Get.to(TransformPage(
                      "酝积分余额",
                      ((controller.assetsDetailBean?.balance ?? 0) +
                              (controller.assetsDetailBean?.frozen ?? 0))
                          .toDouble(),
                      controller.assetsDetailBean?.transferLimit ?? false,
                      "积分互转"));
                },
                width: 200.width,
                color: Color(0xFFF9B57B),
                borderRadios: 40.radius,
              ),
              Spacer(),
            ],
          ),
        )
      ],
    );
  }

  Widget _buildBottomTwo() {
    return Column(
      children: [
        Divider(
          color: Color(0xFFE8D1D1),
          height: 1.width,
        ),
        Container(
          color: Colors.white,
          padding: MarginPaddingUtil.symmetric(
            vertical: 21,
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              ButtonCommon(
                text: '提取',
                onTap: () {
                  Get.to(ChargePage(
                    barTitle: "绿色积分提取",
                    title: "绿色积分",
                    left: "聚星同辉",
                    right: "众商通",
                    btnStr: "确定提取",
                    bgImage: "ic_duibg",
                    controller: controller.textEditingController,
                    btnColor: Color(0xFF9EC573),
                    callback: () {
                      controller.withdraw();
                    },
                    inputBgColor: Color(0xFF8DB55F),
                  ));
                },
                width: 200.width,
                color: Color(0xFF9EC573),
                borderRadios: 40.radius,
              ),
              10.widthBox,
              ButtonCommon(
                text: '兑换',
                onTap: () {
                  Get.to(ExchangePage(controller.assetsDetailBean));
                },
                width: 200.width,
                color: Color(0xFF9EC573),
                borderRadios: 40.radius,
              ),
              10.widthBox,
              ButtonCommon(
                text: '互转',
                onTap: () {
                  Get.to(TransformPage(
                      "绿色积分互转",
                      ((controller.assetsDetailBean?.balance ?? 0) +
                              (controller.assetsDetailBean?.frozen ?? 0))
                          .toDouble(),
                      controller.assetsDetailBean?.transferLimit ?? false,
                      "积分互转"));
                },
                width: 200.width,
                color: Color(0xFF9EC573),
                borderRadios: 40.radius,
              ),
            ],
          ),
        )
      ],
    );
  }

  Widget _buildBottomThree() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Divider(
          color: Color(0xFFE8D1D1),
          height: 1.width,
        ),
        Container(
          width: Get.width,
          color: Colors.white,
          padding: MarginPaddingUtil.symmetric(
            vertical: 21,
          ),
          child: UnconstrainedBox(
            child: ButtonCommon(
              text: '互转',
              onTap: () {
                Get.to(ScoreTransform(
                  amount: ((controller.assetsDetailBean?.balance ?? 0) +
                          (controller.assetsDetailBean?.frozen ?? 0))
                      .toDouble(),
                ));
              },
              width: 200.width,
              color: Color(0xFFFE8E78),
              borderRadios: 40.radius,
            ),
          ),
        )
      ],
    );
  }

  Widget _buildBottomFour() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Divider(
          color: Color(0xFFE8D1D1),
          height: 1.width,
        ),
        Container(
          width: Get.width,
          color: Colors.white,
          padding: MarginPaddingUtil.symmetric(
            vertical: 21,
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ButtonCommon(
                text: '提取',
                onTap: () {
                  Get.to(ChargePage(
                    barTitle: "众商通提取",
                    title: "众商通提取",
                    left: "聚星同辉",
                    right: "众商通",
                    btnStr: "确定提取",
                    bgImage: "ic_duibg1",
                    controller: controller.textEditingController,
                    btnColor: Color(0xFFFC9B49),
                    callback: () {
                      controller.withdraw();
                    },
                    inputBgColor: Color(0xFFFC9B49),
                  ));
                },
                width: 200.width,
                color: Color(0xFFFFA353),
                borderRadios: 40.radius,
              ),
              10.widthBox,
              ButtonCommon(
                text: '互转',
                onTap: () {
                  Get.to(TransformPage(
                    "众商通互转",
                    ((controller.assetsDetailBean?.balance ?? 0) +
                            (controller.assetsDetailBean?.frozen ?? 0))
                        .toDouble(),
                    controller.assetsDetailBean?.transferLimit ?? false,
                    "众商通互转",
                  ));
                },
                width: 200.width,
                color: Color(0xFFFFA353),
                borderRadios: 40.radius,
              ),
            ],
          ),
        )
      ],
    );
  }

  Widget _buildBottomFive() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Divider(
          color: Color(0xFFE8D1D1),
          height: 1.width,
        ),
        Container(
          width: Get.width,
          color: Colors.white,
          padding: MarginPaddingUtil.symmetric(
            vertical: 21,
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ButtonCommon(
                text: '增值',
                onTap: () {
                  Get.to(ZengZhi(
                    callback: () {
                      controller.getAssetsDetail();
                    },
                  ));
                },
                width: 200.width,
                color: Color(0xFF6DCCF0),
                borderRadios: 40.radius,
              ),
              10.widthBox,
              ButtonCommon(
                text: '增值记录',
                onTap: () {
                  Get.to(ZengZhiHistory());
                },
                width: 200.width,
                color: Color(0xFF6DCCF0),
                borderRadios: 40.radius,
              ),
            ],
          ),
        )
      ],
    );
  }
}
